require(['util', 'validator'], function () {
        var $safetyEvalForm = $("#safetyEvalForm");

        var seleOrgan = {},
            corpId = "";

        $("#showData").hide();

        //左侧树点击事件
        commonFun.leftTreeNodeClickObj['safetyEvalTab'] = function(event, treeId, treeNode) {
            if(treeNode.type === 'CAR' || treeNode.type === 'DRIVER'){
                $.messager.alert("提示","请选择组织机构或线路，进行参数设置。","info");
                return;
            }
            seleOrgan = treeNode;
            corpId = treeNode.corpId;
            showInterface();
        };

        //根据后台返回的数据，动态生成界面
        var showInterface = function(){
            $.ajaxExt({
                url : "/safetyEval/searchSafetyEvalInfo.htm",
                data : {"corpId":corpId, "organId":seleOrgan.id}
            }).done(function(data){
                var currData = data;
                //清空界面，后面再根据数据渲染界面
                $("#u_tip").remove();
                $("#sele_msg").empty();
                $('#accWV').empty();
                $('#illWV').empty();
                $('#accScoreWV').empty();
                $('#illScoreWV').empty();
                $('#accDedPoint').empty();
                $('#illDedPoint').empty();
                $('#accScoreAC').empty();
                $('#illScoreAC').empty();
                //显示界面
                $("#showData").show();
                $("#safetyEvalBnt").show();
                //根据数据渲染界面
                var seleOrganId = seleOrgan.id,
                    currOrganId = currData[0].organLineId;
                $("#sele_msg").append("<h1 class='line-title'>【"+seleOrgan.name+"】的安保考核参数设置信息</h1>");
                $("#sele_msg").append("<input type='hidden' name='seleId' value='"+seleOrganId+"'/>"
                +"<input type='hidden' name='corpId' value='"+corpId+"'/>"
                +"<input type='hidden' name='currId' value='"+currOrganId+"'/>");
                $.each(currData,function(n,entity){
                    if(entity.chkCgyCode === 'CHK04000'){

                        $("#illScoreWV").append("<input type='hidden' name='chkIds' value='"+entity.chkId+"'/>");
                        $('#illScoreWV').append("<li>"
                        +"<label class='label-text'>违章评分权重("+entity.paramValue+"~"+entity.paramValue2+"分)：</label>"
                        +"<input type='text' name='illScoreWVs' class='input-text' data-validator='{required:true,number:true}' value='"+entity.weightValue+"'/> %"
                        +"</li>");
                        $('#illDedPoint').append("<li>"
                        +"<label class='label-text'>发生违章扣分("+entity.paramValue+"~"+entity.paramValue2+"分)：</label>"
                        +"<input type='text' name='illDedPoints' class='input-text'  data-validator='{required:true,number:true}' value='"+entity.deductValue+"'/>"
                        +"</li>");
                        $('#illScoreAC').append("<li>"
                        +"<label class='label-text'>允许违章次数("+entity.paramValue+"~"+entity.paramValue2+"分)：</label>"
                        +"<input type='text' name='illScoreACs' class='input-text'  data-validator='{required:true,number:true}' value='"+entity.allowCount+"'/>"
                        +"</li>");
                    }
                    if(entity.chkCgyCode === 'CHK05000'){
                        $("#accScoreWV").append("<input type='hidden' name='chkIds' value='"+entity.chkId+"'/>");
                        $('#accScoreWV').append("<li>"
                        +"<label class='label-text'>事故评分权重("+entity.paramValue+"~"+entity.paramValue2+"元)：</label>"
                        +"<input type='text' name='accScoreWVs' class='input-text'  data-validator='{required:true,number:true}' value='"+entity.weightValue+"'/> %"
                        +"</li>");
                        $('#accDedPoint').append("<li>"
                        +"<label class='label-text'>发生事故扣分("+entity.paramValue+"~"+entity.paramValue2+"元)：</label>"
                        +"<input type='text' name='accDedPoints' class='input-text'  data-validator='{required:true,number:true}' value='"+entity.deductValue+"'/>"
                        +"</li>");
                        $('#accScoreAC').append("<li>"
                        +"<label class='label-text'>允许事故次数("+entity.paramValue+"~"+entity.paramValue2+"元)：</label>"
                        +"<input type='text' name='accScoreACs' class='input-text'  data-validator='{required:true,number:true}' value='"+entity.allowCount+"'/>"
                        +"</li>");
                    }
                    if(entity.chkCgyCode === 'CHK06000'){
                        if(entity.chkCode === 'CHK06001'){
                            $("#accWV").append("<input type='hidden' name='chkIds' value='"+entity.chkId+"'/>");
                            $("#accWV").append("<li>"
                            +"<label class='label-text'>事故权重：</label>"
                            +"<input type='text' name='accIllWVs' class='input-text'  data-validator='{required:true,number:true}' value='"+entity.weightValue+"'/> %"
                            +"</li>");
                        }
                        if(entity.chkCode === 'CHK06002'){
                            $("#illWV").append("<input type='hidden' name='chkIds' value='"+entity.chkId+"'/>");
                            $("#illWV").append("<li>"
                            +"<label class='label-text'>违章权重：</label>"
                            +"<input type='text' name='accIllWVs' class='input-text'  data-validator='{required:true,number:true}' value='"+entity.weightValue+"'/> %"
                            +"</li>");
                        }
                    }
                });
            });
        };

        $("#safetyEval_update").on("click", function(){
            if($.validator($('#safetyEvalForm'))){
                $.messager.confirm("是否修改","确定修改该机构所对应的安保考核参数？",function(r){
                    if(r){
                        var formData = $safetyEvalForm.serialize();
                        $.ajaxExt({
                            url :"/safetyEval/uptSafetyEvalInfo.htm",
                            data : formData
                        }).done(function(data){
                        });
                    }
                });
            }
        });

        $("#safetyEval_reset").on("click", function(){
            showInterface();
        });
        
        //页面打开自动查询
        var nodes = commonFun.getLeftTreeSelectedNodes();
    	if(nodes.length<1||nodes[0].type==="LINE"){
    		seleOrgan = nodes[0];
            corpId = nodes[0].corpId;
            showInterface();
    	}
})